<?
/**
 * Add Item Template
 */
(basename($_SERVER['PHP_SELF']) == basename(__FILE__)) && die('Access Denied');

// title
$this->setTitle(WEB_APP_NAME . ' : ' . OPT_ADD);

// validate required template variables
$item = $this->getVar('item');
if (!($item instanceof Event)) {
	die($this->getPageError('Item instance is missing.'));
	}

// Are there errors?
$hasErrors = (is_array($this->getErrors()) and count($this->getErrors()));

// generate boilerplate html
$class = '';
$this->addCss('css/calendar.css');
$this->addJs('js/calendar.js');
$this->addJs('js/menu.js');
$this->addJs('js/util.js');
?>
<?= $this->getPageHeader(); ?>
<? if ($hasErrors) { ?>
<div id="container-error">
<?= implode('<br />', $this->getErrors()); ?>
</div>
<? } ?>
<div align="center">
<div id="page-container">

<div id="container-medium">
<?= getMenuBars(OPT_ADD); ?>
</div>

<div id="container-medium">
<div class="content-edit">

<?= $this->getFormHeader('item_form'); ?>
<?= $this->getFormBreadCrumbs(); ?>
<input type="hidden" name="<?= WA_QS_CONFIRM; ?>" value="yes">

<table cellpadding="2" cellspacing="2">
	<tr>
		<td class="category" colspan="2">
			Event Identification
		</td>
	</tr>
<? $prop = 'EventDate'; ?>
	<tr>
		<th>
			<?= htmlspecialchars($item->getPropertyDescription($prop)); ?>
		</th>
		<td>
			<?= getDatePicker(); ?>
		</td>
	</tr>
<? $prop = 'CategoryId'; ?>
<? $new = (isset($_REQUEST['CategoryNew'])) ? $_REQUEST['CategoryNew'] : ''; ?>
	<tr>
		<th>
			<?= htmlspecialchars($item->getPropertyDescription($prop)); ?>
		</th>
		<td>
			<?= selectCategoryId('CategoryId', $item->CategoryId()); ?>
			or Add: <input type="text" name="CategoryNew" value="<?= htmlspecialchars($new); ?>">
		</td>
	</tr>
<? $prop = 'EventText'; ?>
	<tr>
		<th colspan="2">
			<?= htmlspecialchars($item->getPropertyDescription($prop)); ?>
		</th>
	</tr>
<? $prop = 'SourceId'; ?>
<? $new = (isset($_REQUEST['SourceNew'])) ? $_REQUEST['SourceNew'] : ''; ?>
	<tr>
		<th>
			<?= htmlspecialchars($item->getPropertyDescription($prop)); ?>
		</th>
		<td>
			<?= selectSourceId('SourceId', $item->SourceId()); ?>
			or Add: <input type="text" name="SourceNew" value="<?= htmlspecialchars($new); ?>">
		</td>
	</tr>
<? $prop = 'EventText'; ?>
	<tr>
		<td colspan="2">
			<textarea cols="40" rows="5" name="<?= $prop; ?>"><?= htmlspecialchars($item->getProperty($prop)); ?></textarea>
		</td>
	</tr>
</table>

<table cellpadding="2" cellspacing="2">
	<tr>
		<td colspan="2" style="text-align: right">
			<input class="submit" type="submit" name="submit" value="Add Event">
		</td>
	</tr>
</table>
<?= $this->getFormFooter(); ?>

</div> <!-- content-edit -->
</div> <!-- container-medium -->
</div> <!-- page-container -->
</div> <!-- center -->
<script type="text/javascript">
doMenuMsg('<?= OPT_ADD; ?>');
document.item_form.EventText.focus();
</script>
<?= $this->getPageFooter(); ?>
